package com.example.login.biz.impl;

import com.example.login.biz.PingLunBiz;
import com.example.login.mapper.PingLunMapper;
import org.example.bean.PinglunInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PingLunBizImpl implements PingLunBiz {
    @Autowired
    private PingLunMapper plm;


    @Override
    public Map<String, Object> findUserByPage(int page) {
        Map<String,Object> map = new HashMap<>();
        List<PinglunInfo> list=plm.findUserByPage((page-1)*5);
        for(PinglunInfo ui:list){
            PinglunInfo pi=plm.finAllTushuId(ui.getTushuid());
            ui.setShuming(pi.getShuming());
        }
        int all = plm.findUserAllCount();
        map.put("rows",list);
        map.put("size",all%5==0?(all/5):(all/5+1));
        return map;
    }

    @Override
    public void deletePingLun(int tushuid) {
        plm.deletePingLun(tushuid);
    }

    @Override
    public void savePingLun( String neirong) {
    plm.savePingLun(neirong);
    }

    @Override
    public Map<String, Object> findAllGuanJianZi(int page) {
        Map<String,Object> map = new HashMap<>();
        int all = plm.findGuanCount();
        map.put("rows",plm.findAllGuanJianZi((page-1)*5));
        map.put("size",all%5==0?(all/5):(all/5+1));
        return map;
    }
}
